package gizmoball;

import java.awt.Graphics;

public class LBrick extends Brick
{
	private int width = 40;
	RecBrick r1;
	RecBrick r2;
	
	
	public LBrick(int x,int y)
	{
		super(x,y);
		r1 = new RecBrick(x-this.width/2,y-this.width/2,this.property,90);
		r2 = new RecBrick(x-this.width/2,y,this.property,0);
	}
	
	public LBrick(int x,int y,int p,int d)
	{
		super(x,y,p,d);
		r1 = new RecBrick(x-this.width/2,y-this.width/2,this.property,90);
		r2 = new RecBrick(x-this.width/2,y,this.property,0);
		if(d == 90)
		{
			this.direction = 0;
			this.rotation();
		}
		else if(d == 180)
		{
			this.direction = 0;
			this.rotation();
			this.rotation();
		}
		else if(d == 270)
		{
			this.direction = 0;
			this.rotation();
			this.rotation();
			this.rotation();
		}
		
	}
	
	public LBrick(LBrick b){
		super(b);
		this.width = b.width;
		this.r1 = new RecBrick(b.r1);
		this.r2 = new RecBrick(b.r2);
	}
	
	public void setProperty(int property) {
		this.property = property;
		r1.setProperty(property);
		r2.setProperty(property);
	}
	
	public void setBricky(int bricky)
	{
		this.bricky = bricky;
		r1.setBricky(this.bricky-this.width/2);
		r2.setBricky(this.bricky);
		if(this.direction == 90)
		{
			this.direction = 0;
			this.rotation();
		}
		else if(this.direction == 180)
		{
			this.direction = 0;
			this.rotation();
			this.rotation();
		}
		else if(this.direction == 270)
		{
			this.direction = 0;
			this.rotation();
			this.rotation();
			this.rotation();
		}
	}
	
	public void setBrickx(int brickx) 
	{
		this.brickx = brickx;
		r1.setBrickx(this.brickx-this.width/2);
		r2.setBrickx(this.brickx-this.width/2);
		if(this.direction == 90)
		{
			this.direction = 0;
			this.rotation();
		}
		else if(this.direction == 180)
		{
			this.direction = 0;
			this.rotation();
			this.rotation();
		}
		else if(this.direction == 270)
		{
			this.direction = 0;
			this.rotation();
			this.rotation();
			this.rotation();
		}
	}
	
	public void paint(Graphics g)
	{	
		r1.paint(g);
		r2.paint(g);
	}
	
	public void rotation()
	{
		direction += 90;
		if(direction == 90)
		{
			r2.bricky = this.bricky - this.width/2;
		}
		else if(direction == 180)
		{
			r1.brickx = this.brickx;
		}
		else if(direction == 270)
		{
			r2.bricky = this.bricky;
		}
		else if(direction == 360)
		{
			direction = 0;
			r1.brickx = this.brickx - this.width/2;
		}
	}
	
	public void large()
	{
		if(width<=80)
		{
			if(this.direction == 0)
		    {
				r1.large();
				r2.large();
				this.width = this.width*2;
				r1.brickx = this.brickx - this.width/2;
				r1.bricky = this.bricky - this.width/2;
				r2.brickx = this.brickx - this.width/2;
				r2.bricky = this.bricky;
		    }
			else if(this.direction == 90)
			{
				r1.large();
				r2.large();
				this.width = this.width*2;
				r1.brickx = this.brickx - this.width/2;
				r1.bricky = this.bricky - this.width/2;
				r2.brickx = this.brickx - this.width/2;
				r2.bricky = this.bricky - this.width/2;
			}
			else if(this.direction == 180)
			{
				r1.large();
				r2.large();
				this.width = this.width*2;
				r1.brickx = this.brickx;
				r1.bricky = this.bricky -this.width/2;
				r2.brickx = this.brickx - this.width/2;
				r2.bricky = this.bricky - this.width/2;
			}
			else
			{
				r1.large();
				r2.large();
				this.width = this.width*2;
				r1.brickx = this.brickx;
				r1.bricky = this.bricky - this.width/2;
				r2.brickx = this.brickx - this.width/2;
				r2.bricky = this.bricky;
			}
		}
	}
	
	public void small()
	{
		if(width>=80)
		{
			if(this.direction == 0)
		    {
				r1.small();
				r2.small();
				this.width = this.width/2;
				r1.brickx = this.brickx - this.width/2;
				r1.bricky = this.bricky - this.width/2;
				r2.brickx = this.brickx - this.width/2;
				r2.bricky = this.bricky;
		    }
			else if(this.direction == 90)
			{
				r1.small();
				r2.small();
				this.width = this.width/2;
				r1.brickx = this.brickx - this.width/2;
				r1.bricky = this.bricky - this.width/2;
				r2.brickx = this.brickx - this.width/2;
				r2.bricky = this.bricky - this.width/2;
			}
			else if(this.direction == 180)
			{
				r1.small();
				r2.small();
				this.width = this.width/2;
				r1.brickx = this.brickx;
				r1.bricky = this.bricky -this.width/2;
				r2.brickx = this.brickx - this.width/2;
				r2.bricky = this.bricky - this.width/2;
			}
			else
			{
				r1.small();
				r2.small();
				this.width = this.width/2;
				r1.brickx = this.brickx;
				r1.bricky = this.bricky - this.width/2;
				r2.brickx = this.brickx - this.width/2;
				r2.bricky = this.bricky;
			}
		}
	}
	
	public int judge(int x,int y,int radius)
	{
		if(r1.judge(x,y,radius)==-1 && r2.judge(x,y,radius)==-1)
			return -1;
		else
		{
			bump = 0;
			if(r1.judge(x,y,radius)==r2.judge(x,y,radius))
				return r1.judge(x,y,radius);
			else if(r1.judge(x,y,radius)!=-1 && r2.judge(x,y,radius)==-1)
				return r1.judge(x,y,radius);
			else if(r1.judge(x,y,radius)==-1 && r2.judge(x,y,radius)!=-1)
				return r2.judge(x,y,radius);
			else
				return r2.judge(x,y,radius);
		}
	}
	
	public int judge(int x,int y){
		if(r1.judge(x, y) != -1)
			return -3;
		else if(r2.judge(x, y) != -1)
			return -3;
		else 
			return -1;
	}
	
}
